using DataOperationClassLibraries;
using ExtensionTools.PublicMethods;
using ExtensionToolsLibraries.PublicClasses.OutputModels;
using Microsoft.AspNetCore.Mvc;
using ServiceWebAPI.Request;

namespace ServiceWebAPI.Controllers;

[Route("[controller]")]
[ApiController]
public class UserController(UserOperation userOperation) : ControllerBase
{
    [HttpPost("register")]
    public async Task<OutputModel<string>> Register([FromBody] User user)
    {
        var result = await userOperation.RegisterUserAsync(user.UserName, user.NormalizedUserName!, (int)user.Role!, user.Password);
        return OutPutMethod<string>.Success(result);
    }

    [HttpPost("login")]
    public async Task<OutputModel<string>> Login([FromBody] User user)
    {
        var result = await userOperation.LoginUserAsync(user.UserName, user.Password);
        return OutPutMethod<string>.Success(result);
    }
}